<template>
    <div>
        <Card :bordered="false" dis-hover class="ivu-mt">
            <div class="setting">
                <p>
                    首次挂号下次回访时间
                    <InputNumber
                        :max="10"
                        :min="1"
                        style="width:80px;margin:0 10px;"
                        v-model="value"
                    ></InputNumber>天后
                </p>
                <p>
                    断诊：未复诊时间
                    <InputNumber
                        :min="1"
                        style="width:80px;margin:0 10px;"
                        v-model="value1"
                    ></InputNumber>天
                </p>
                <p>
                    流失：消费金额 &#60;=
                    <InputNumber
                        :min="1"
                        style="width:80px;margin:0 10px;"
                        v-model="value2"
                    ></InputNumber>元
                </p>
                <p>
                    咨询号号段首位数字为
                    <Input v-model="value3" style="width:300px;margin:0 10px;" placeholder="支持输入数字、字母，多个用逗号隔开"></Input>
                </p>
                <p>
                    介绍号号段首位数字为
                    <Input v-model="value5" style="width:300px;margin:0 10px;" placeholder="支持输入数字、字母，多个用逗号隔开"></Input>
                </p>
                <p>
                    所属客服就诊类型
                    <Select v-model="value4" multiple :max-tag-count="3" style="width:300px;margin:0 10px;">
                        <Option v-for="item in typeList" :value="item.id" :key="item.id">{{ item.outpatient_name }}</Option>
                    </Select>
                </p>
            </div>
        </Card>
        <FooterToolbar>
            <Button type="primary" class="v-mt-20" size="large" @click="handleConfig">保存</Button>
        </FooterToolbar>
    </div>
</template>

<script>
    import { GetGlobalConfig, UpdateGlobalConfig } from '@api/setting';

    export default {
        name: 'diagnosis',
        data () {
            return {
                value: 1,
                value1: 1,
                value2: 1,
                value3: '',
                value4: '',
                value5: '',
                typeList: []
            }
        },
        created () {
            this.getConfigInfo()
        },
        methods: {
            getConfigInfo () {
                GetGlobalConfig().then((res) => {
                    if (res.list && res.list.length > 0) {
                        res.list.forEach((item) => {
                            if (item.hasOwnProperty('global_initial_visit_time')) {
                                this.value = parseInt(item['global_initial_visit_time']);
                            } else if (item.hasOwnProperty('global_no_therapy_time')) {
                                this.value1 = parseInt(item['global_no_therapy_time']);
                            } else if (item.hasOwnProperty('global_loss_amout_money')) {
                                this.value2 = parseInt(item['global_loss_amout_money']);
                            } else if (item.hasOwnProperty('global_card_consult')) {
                                this.value3 = item['global_card_consult'];
                            } else if (item.hasOwnProperty('global_customer_outpatient_type')) {
                                this.value4 = item['global_customer_outpatient_type'].split(',')
                            } else if (item.hasOwnProperty('global_card_introduce')) {
                                this.value5 = item['global_card_introduce']
                            }
                        })
                    }
                    this.typeList = res.outpatient_type
                }).catch(() => {})
            },
            handleConfig () {
                this.$Modal.confirm({
                    title: '确定修改当前全局配置?',
                    width: '300',
                    onOk: () => {
                        this.changeSubmit();
                    }
                });
            },
            changeSubmit () {
                const params = {
                    global_initial_visit_time: `${this.value}`,
                    global_no_therapy_time: `${this.value1}`,
                    global_loss_amout_money: `${this.value2}`,
                    global_card_consult: `${this.value3}`,
                    global_customer_outpatient_type: `${this.value4}`,
                    global_card_introduce: `${this.value5}`
                }
                UpdateGlobalConfig(params).then((res) => {
                    this.$Message.success('保存成功');
                }).catch(() => {})
            }
        }
    }
</script>

<style scoped>
.setting p {
    line-height: 30px;
    margin: 20px 0;
}
.setting input {
    margin: 0 10px;
}
</style>
